﻿using D.TestKill15.NLogsUtil;
using Microsoft.AspNetCore.Mvc;

namespace D.TestKill15
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        INLogService _nLogService;
        public TestController(INLogService nLogService)
        {
            _nLogService = nLogService;
        }

        [HttpGet("get")]
        public async Task<string> Get(int? delayTime)
        {
            var t = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")}-收到消息";
            _nLogService.Info(t);
            await Console.Out.WriteLineAsync(t);

            if (delayTime != null)
            {
                var s = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")}-开始执行函数需要耗费{delayTime}ms";
                _nLogService.Info(s);
                await Console.Out.WriteLineAsync(s);

                await Task.Delay(delayTime.Value);
                var e = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")}-函数执行{delayTime}ms完毕";
                _nLogService.Info(e);
                await Console.Out.WriteLineAsync(e);
            }

            var r = $"返回消息：{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")}";
            await Console.Out.WriteLineAsync(r);
            return r;
        }
    }
}

